<template>
	<view class="module flex_ZC">
		<NavTitle :title="title" :backgroundColor='backgroundColor' @leftClick="leftClick"></NavTitle>

		<view class="describe describe_blue">
			<view class="">
				<image :src="baseUrl + '/static/ymimage/remind1.png'" class="remind" mode="aspectFill">
				</image>
			</view>
			<view class="">请使用法人微信或支付宝账号的“扫一扫”功能，扫描以下二维码完成授权。请至少完成一项认证，推荐全部完成。</view>
		</view>
		<view class="supplement " v-if="types == 1">
			<text class="f32 c3 fw7">微信</text>
			<view class="flex_ZC">
				<view v-if="wxAtInfo.qrcode_data">
					<image class="atimg mt32" :src="'data:image/png;base64,'+ wxImg" :show-menu-by-longpress="true"
						@longpress="handleLongPress" mode="aspectFill"></image>
				</view>
				<view class="fail" v-if="wxAtInfo.wxCode == 0">
					<text class="f24">{{wxAtInfo.wxerrMsg}}</text>
				</view>
				<view class="" v-else>
					<view class="fail flex_Z" v-if="wxAtInfo.applyment_stat == 'APPLYMENT_STATE_REJECTED'">
						<text class="f28">{{wxAtInfo.reject_reason}} 请联系客服人员协助解决 </text>
					</view>
					<view class="state_box flex_Z" v-else>
						<view class="" v-if="wxAtInfo.applyment_stat == 'APPLYMENT_STATE_FREEZED'">
							<text class="f28">已认证 </text>
						</view>
						<view class="" v-else>
							<text class="f28">{{wxAtInfo.applyment_stat_name}} </text>
							<text class="f24">{{wxAtInfo.applyment_stat_desc}} </text>
						</view>

					</view>
				</view>

			</view>

		</view>


		<view class="supplement " v-else>
			<text class="f32 c3 fw7">支付宝</text>
			<view class=" flex_ZC">
				<view v-if="zfbImg">
					<image class="zfbimg mt56" :src="zfbImg" :show-menu-by-longpress="true" @longpress="handleLongPress"
						mode="aspectFill"></image>
				</view>
				<view class="fail" v-if="zfbAtInfo.appplyCode == 0">
					<text class="f24">{{zfbAtInfo.applyerrMsg}}</text>
				</view>
				<view class="" v-else>
					<view class="fail flex_Z" v-if="zfbAtInfo.order_status == 'AUDIT_REJECT'">
						<view class=" flex_Z">
							<text class="f28">{{JSON.parse(zfbAtInfo.reject_reason)[0].fail_reason}} 请联系客服人员协助解决</text>
						</view>
					</view>
					<view class="state_box flex_Z" v-else>
						<text class="f28">{{zfbAtInfo.order_status_name}} </text>
						<text class="f24">{{zfbAtInfo.resp_desc}}</text>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		tRealNameQuery,
		aRealNameQuery,
		settledDetails
	} from '@/api/settled.js'
	export default {
		data() {
			return {
				title: "商户实名认证",
				backgroundColor: "",
				baseUrl: this.$imageBaseUrl,
				wxImg: '',
				zfbImg: '',
				wxAtInfo: {
					wxCode: 0,
					wxerrMsg: "",
					applyment_stat_name: '加载中...',
					applyment_stat_desc: '加载中...',
					reject_reason: '加载中...',
				},
				zfbAtInfo: {
					appplyCode: 0,
					applyerrMsg: "",
					order_status_name: '加载中...',
					resp_desc: '加载中...',
					reject_reason: [{
						fail_param: '加载中...',
						fail_reason: '加载中...'
					}]
				},
				types: 1
			}
		},
		// 页面滚动
		onPageScroll: function(e) {
			const scrollTop = e.scrollTop; // 获取页面滚动位置
			// 根据滚动位置修改状态栏样式
			if (scrollTop > 20) {
				this.backgroundColor = '#ffffff';
			} else {
				this.backgroundColor = '';
			}
		},
		onLoad(options) {
			if (options.type) {
				this.types = options.type
				if (options.type == 1) {
					this.tRealNameQuery()
				} else {
					this.aRealNameQuery()
				}
			}
		},
		// onBackPress(options) {
		// 	// 监听返回按钮事件
		// 	console.log('返回按钮被点击', options)
		// 	return false
		// 	// this.leftClick()

		// 	// // 阻止默认返回行为
		// 	// setTimeout(()=>{
		// 	// 	return true
		// 	// },1500)
		// },
		onUnload() {
			uni.setStorageSync('routeUrl', 'pageYm/ymJoin/ymATAuthorize')
		},
		methods: {
			
			tRealNameQuery() {
				tRealNameQuery().then(res => {
					console.log('wx--', res);
					this.wxAtInfo.wxCode = res.code
					if (res.code == 1) {
						this.wxAtInfo = res.data
						this.wxImg = res.data.qrcode_data
					}
					if (res.code == 0) {
						this.wxAtInfo.wxerrMsg = res.msg + '请联系客服人员协助解决'
					}
				})
			},
			aRealNameQuery() {
				aRealNameQuery().then(res => {
					this.zfbAtInfo.appplyCode = res.code
					if (res.code == 1) {
						this.zfbAtInfo = res.data
						this.zfbImg = res.data.qrcode
					}
					if (res.code == 0) {
						this.zfbAtInfo.applyerrMsg = res.msg + '请联系客服人员协助解决'
					}
				})
			},
			async leftClick() {
				
				const canNavBack = getCurrentPages()
				console.log(canNavBack);
				// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				if (canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.switchTab({
						url: '/pages/index/cloudCatIndex'
					})
				}
				
				//获取页面栈的长度
				// uni.showLoading({
				// 	title: '正在同步...',
				// 	mask: true
				// })
				// const detailsResult = await this.gettledDetails()
				// if (detailsResult.code == 1) {
				// 	uni.setStorageSync('ymShopDetails', JSON.stringify(detailsResult.data))
				// 	const canNavBack = getCurrentPages()
				// 	console.log(canNavBack.length);
				// 	// 判断是否刷新了浏览器，刷新了浏览器，页面栈只有当前一个
				// 	if (canNavBack.length > 1) {
				// 		uni.navigateBack({
				// 			delta: 1
				// 		})
				// 	} else {
				// 		uni.switchTab({
				// 			url: '/pages/index/cloudCatIndex'
				// 		})
				// 	}
				// }
			},
			gettledDetails() {
				return new Promise((resolve, reject) => {
					settledDetails().then(res => {
						if (res.code == 1) {
							resolve(res)
						}
					})
				})
			}
		}
	}
</script>

<style scoped>
	.module {
		width: 750rpx;
		margin: 0 auto;
		padding: 0 32rpx;
	}

	.information_txt {
		width: 686rpx;
		padding: 16rpx 0;
	}

	.describe {
		width: 686rpx;
		border-radius: 10rpx;
		font-size: 22rpx;
		margin: 8rpx 0;
		padding: 8rpx 16rpx;
		display: flex;
		align-items: flex-start;
	}

	.describe_blue {
		background: rgba(1, 146, 250, 0.1);
		color: #0192FA;
	}

	.remind {
		width: 22rpx;
		height: 22rpx;
		margin-right: 8rpx;
		margin-top: 7rpx;
	}

	.supplement {
		width: 686rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(0, 0, 0, 0.04);
		border-radius: 14rpx 14rpx 14rpx 14rpx;
		padding: 24rpx 32rpx;
		margin-top: 24rpx;
	}

	.lanse {
		display: flex;
		align-items: baseline;
		padding: 16rpx 16rpx;
		width: 690rpx;
		background: #EEF1FF;
		border-radius: 6rpx 6rpx 6rpx 6rpx;
		margin: 14rpx 0;
	}

	.lanse>text {
		margin-left: 10rpx;
	}

	.atimg {
		width: 612rpx;
		height: 612rpx;
	}

	.zfbimg {
		width: 550rpx;
		height: 550rpx;
	}

	.mt32 {
		margin-top: 32rpx;
	}

	.mt56 {
		margin-top: 56rpx;
	}

	.state_box {
		width: 650rpx;
		background: #e1faba;
		border-radius: 6rpx;
		color: #78C400;
		padding: 10rpx;
	}

	.state_box>text {
		margin-top: 6rpx;
	}

	.fail {
		width: 650rpx;
		background: #FFF5EE;
		border-radius: 6rpx;
		color: #FA6E01;
		padding: 10rpx;
		margin-top: 30rpx;
	}

	.fail>text {
		margin-top: 6rpx;
	}
</style>